package com.great.controller;

import com.github.pagehelper.PageInfo;
import com.great.dao.IndexDao;
import com.great.domain.Order;
import com.great.service.OrderService;
import org.omg.CORBA.PRIVATE_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author huangwenkai
 * @date 2021/10/19 10:04
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private IndexDao indexDao;

    @GetMapping("/findAllOrder")//查询所有订单
    public ModelAndView findAllOrder(@RequestParam(name = "page", required = true,defaultValue = "1") int page, @RequestParam(name = "size",required = true,defaultValue = "5") int size){
        ModelAndView mv = new ModelAndView("/manage/order-list");
        List<Order> orders = orderService.findAllOrder(page, size);
        PageInfo pageInfo = new PageInfo(orders);
        mv.addObject("pageInfo",pageInfo);
        mv.addObject("orders",orders);
        return mv;
    }

    @RequestMapping("/transmit")
    public ModelAndView transmit(String order_id,@RequestParam(name = "page", required = true,defaultValue = "1") int page, @RequestParam(name = "size",required = true,defaultValue = "5") int size){
        ModelAndView mv = new ModelAndView("/manage/order-list");
        indexDao.transmit(order_id);
        List<Order> orders = orderService.findAllOrder(page, size);
        PageInfo pageInfo = new PageInfo(orders);
        mv.addObject("pageInfo",pageInfo);
        mv.addObject("orders",orders);
        return mv;
    }
}
